package com.bitoon.basketdudes.web;

import java.io.*;
import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

public class Upload extends BaseActionServletAware {

    private File filedata;
    private String filedataContentType;
    private String filedataFileName;
    private String fileJsessionid;
    private Logger log = Logger.getLogger(Upload.class);

    @Override
    public String execute() {

        try {
            String filenameDestino = ServletActionContext.getServletContext().getRealPath("/temp/") + "/" + fileJsessionid + ".jpg";
            //log.debug("Intentando copiar en sesion: " + filenameDestino);
            File destino = new File(filenameDestino);
            FileUtils.copyFile(this.filedata, destino);
        } catch (Exception e) {
            log.error("no se pudo copiar: " + e);
        }

        return SUCCESS;
    }

    public File getFiledata() {
        return filedata;
    }

    public void setFiledata(File filedata) {
        this.filedata = filedata;
    }

    public String getFiledataContentType() {
        return filedataContentType;
    }

    public void setFiledataContentType(String filedataContentType) {
        this.filedataContentType = filedataContentType;
    }

    public String getFiledataFileName() {
        return filedataFileName;
    }

    public void setFiledataFileName(String filedataFileName) {
        this.filedataFileName = filedataFileName;
    }

    public String getFileJsessionid() {
        return fileJsessionid;
    }

    public void setFileJsessionid(String fileJsessionid) {
        this.fileJsessionid = fileJsessionid;
    }

}
